<?
global $db,$user;

inc_inclib("query.php");
$users = query2map($db->query("select id,title from users order by title"),"id","title");

#$nodes = query2map($db->query("select id,title from node where modules_id = 4"),"id","title");
$r = $db->query("select id,modules_id,title as _title,parentid as _parentid from node where folderid = 1 order by orders,title");

$nodes = array();

$more=array();
foreach ($r as $m) $more[$m["_parentid"]][$m["id"]]=$m;

$out=array_reverse($more[0]);
while (count($out)) {
        $e=array_pop($out);
        if (isset($more[$e["id"]])) {
		$a = array_reverse($more[$e["id"]]);
	       foreach ($a as $k=>$ee) $a[$k]["level"] = $e["level"]+1;
	       array_splice($out,count($out),0,$a);
               }
	if ($e["modules_id"] == 4) {
		$ee = $e; $t = ""; 
		while ($ee["id"]) { $t = ($t==""?$ee["_title"]:"{$ee["_title"]} > $t"); $ee = $r[$ee["_parentid"]]; }
		$nodes[$e["id"]] = $t;
		}
	}



$f = array(
/*	"node_id"=>array(
		"title"=>"Category",
		"type"=>"select",
		"options"=>$nodes,
		"required"=>1,
		),*/
	"title"=>array(
		"title"=>"Name",
		"type"=>"default",
		#"size"=>36,
		"size"=>"36",
		"required"=>1,
		),
        "tags"=>array(
            "title"=>"Tags",
            "required"=>1,
            "type"=>"tags",
            "special"=>1,
            ),
	
	"datetimeon"=>array(
		"title"=>"Date",
		"type"=>"timestamp",
		"special"=>1,
		"display"=>"none",
		"_view"=>array("display"=>"view"),
		),

	/*
	"abbv"=>array(
		"title"=>"Abbv.",
		"type"=>"default",
		"append"=>1,
		"size"=>12,
		"required"=>1,
		),
	*/
		
	"users_id"=>array(
		"title"=>"Owner",
		"type"=>"select",
		"options"=>$users,
		"default"=>$user["id"],
		"display"=>"hidden",
		),
		
	"image"=>array(
		"title"=>"Image",
		"type"=>"shot",
		"special"=>1,
		),
		
	"summary"=>array(
		"title"=>"Summary",
		"type"=>"textarea",
		"rows"=>3,
		"required"=>1,
		),

		
	"description"=>array(
		"title"=>"Description",
		"type"=>"textarea",
		"required"=>1,
		),

	"uri"=>array(
		"title"=>"Home Page", 
		"type"=>"default",
		"note"=>"e.g. http://www.pygame.org/",
		"regex"=>"\\:\\/\\/",
		"regex_error"=>"You must enter a valid URI.",
		"required"=>1,
		),
		
	/*
	"cvsroot"=>array(
		"title"=>"CVS Root",
		"type"=>"default",
		),
	*/
	);
	
$rf = array(
	"release"=>array(
		"display"=>"none",
		"type"=>"release",
		"special"=>1,
		),
	"release[title]"=>array(
		"comments"=>"<h2>Initial Release Information</h2>",
		"title"=>"Version",
		"type"=>"default",
		"size"=>8,
		"special"=>1,
		#"_new"=>array("required"=>1),
		),
	"release[srcuri]"=>array(
		"title"=>"Source URI",
		"type"=>"default",
		"special"=>1,
		"regex"=>"\\:\\/\\/",
		"regex_error"=>"You must enter a valid URI.",
		),
	"release[winuri]"=>array(
		"title"=>"Windows URI",
		"type"=>"default",
		"special"=>1,
		"regex"=>"\\:\\/\\/",
		"regex_error"=>"You must enter a valid URI.",
		),
	"release[macuri]"=>array(
		"title"=>"Mac URI",
		"type"=>"default",
		"special"=>1,
		"regex"=>"\\:\\/\\/",
		"regex_error"=>"You must enter a valid URI.",
		),
	);

if (intval($params["id"]) == 0) {
	$f = array_merge($f,$rf);
	}
	
return array(
	"fields"=>$f,
	"table"=>"project",
	"title"=>"Project",
	"titles"=>"Projects",
	"key"=>"id",
	"field"=>"title",
	"upload"=>1,
	);
?>
